package com.ruoyi.project.opencv.test.http;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.ruoyi.common.utils.http.HttpClientUtil;
import org.apache.commons.codec.binary.Base64;

import java.util.Map;

public class HttpBasicAuth {

    public static final String APPID = "XyPFYG4GkL2Ammehc";
    public static final String APPKEY = "5Mjilpnp4fAyy4jLok2vAIMMGh1beKKk";

    public static String getAccessToken() throws Exception {
        Map<String, String> header = Maps.newHashMap();

        String base64UserMsg = Base64.encodeBase64String((APPID + ":" + APPKEY).getBytes());

        String authorization="Basic "+base64UserMsg;

        header.put("Content-Type","application/json");
        header.put("Authorization",authorization);

        String result = HttpClientUtil.sendPost("http://neuron-epidemic.wiot.tech:8800/oauth/token?grant_type=password&username=lingxi&password=W-W6JNOr3A",60000,60000,header,null,null);
        JSONObject json = JSON.parseObject(result);
        System.out.println(json);
        return null;
    }

    public static void main(String[] args) throws Exception {
        System.out.println(getAccessToken());
    }
}
